//check input zipcode, return true/false
var MAX_OPTIONS = 3;
var max_waiting = 100;
var wait_time = 700;
var isBlockUI = false;
function validateZipcode(evt){
	var keyCode = (evt.which)?(evt.which):(evt.keyCode);

	if ( ((keyCode > 47) && (keyCode < 58)) //number
		|| keyCode==37 || keyCode==39 || keyCode==45	//left, right, dash 
		|| keyCode==8 || keyCode==46 || keyCode==9 ) 	//delete,backspace, tab
	{
		return true;
	}
	else
	{
		// Prevents default action from Occuring in IE5+
		if (evt.returnValue)
		{
			evt.returnValue = false;
		}

		// Prevents default action from Occuring in NN6+
		if (evt.preventDefault)
		{
			evt.preventDefault();
		}
		return false;
	}
}
//check input is number, return true/false
function validateKeyPressIsNumber(evt){
	var keyCode = (evt.which)?(evt.which):(evt.keyCode);
	if ( ((keyCode > 47) && (keyCode < 58)) //number
		|| keyCode==37 || keyCode==39 	//left, right 
		|| keyCode==8 || keyCode==46 || keyCode==9 ) 	//delete,backspace, tab
	{
		return true;
	}
	else
	{
		// Prevents default action from Occuring in IE5+
		if (evt.returnValue)
		{
			evt.returnValue = false;
		}

		// Prevents default action from Occuring in NN6+
		if (evt.preventDefault)
		{
			evt.preventDefault();
		}
		return false;
	}
}
//check input is weight,money,height , return true/false
function validateKeyPressIsRealNumber(evt){
	var keyCode = (evt.which)?(evt.which):(evt.keyCode);

	if ( ((keyCode > 47) && (keyCode < 58)) //number
		|| keyCode==190 // period = dot
		|| keyCode==37 || (keyCode==39 && evt.charCode==0) 	//left, right (charCode to check ' )
		|| keyCode==8 || keyCode==46 || keyCode==9 ) 	//delete,backspace, tab
	{
		return true;
	}
	else
	{
		// Prevents default action from Occuring in IE5+
		if (evt.returnValue)
		{
			evt.returnValue = false;
		}

		// Prevents default action from Occuring in NN6+
		if (evt.preventDefault)
		{
			evt.preventDefault();
		}
		return false;
	}
}
function parseToCurrencyNumDefaultZero(element){
	parseToCurrencyNum(element);
	if(element.value == '') element.value = '0.00'
}
function parseToCurrencyNum(element){
	var num = element.value;	
	if(num != "" && isNaN(num) || num < 0){		
		element.value = '';			
		element.focus();
		element.select();	
	}else if(element.value != ""){	
		element.value = decimalFormatted(element.value);
	}else if(element.value == ""){
		element.value = '0.00';
	}
}

function parseToCurrencyNumDefaultBlank(element){
	parseToCurrencyNum(element);
	if(element.value == '0.00') element.value = ''
}

function parseToCurrencyNumDefaultZeroNegative(element){
	parseToCurrencyNumNegative(element);
	if(element.value == '') element.value = '0.00'
}
function parseToCurrencyNumNegative(element){
	var num = element.value;	
	if(num != "" && isNaN(num)){		
		element.value = '';			
		element.focus();
		element.select();	
	}else if(element.value != ""){	
		element.value = decimalFormatted(element.value);
	}else if(element.value == ""){
		element.value = '0.00';
	}
}
function decimalFormatted(amount){
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}
function formatCurrency(num){
	var rs = "0.00";	
	if (!isNaN(num)) {
		if(num > 0 && num < 1){
			num = "0" + num;
		}
		var specialCase = false;
		if(num < 0 && num > -1){
			specialCase = true;
		}
		var intNum = parseInt(num);
		if(isNaN(intNum)) intNum = 0;			
		if(num < 0) num = -num;	
		var decNum = '' + parseInt(Math.round((num * 100) % 100), 10);
		
		while (decNum.length < 2) {
			decNum = '0' + decNum;
		}
		if(decNum < 0) decNum = -decNum;
		rs = (specialCase ? "-" : "") + intNum + "." + decNum;
	}
	return rs;
}
function populateChargePayment(){
	//1
	gross_rental_receipts=$('#gross_rental_receipts').val();
	if(gross_rental_receipts=='')gross_rental_receipts=0;
	//2
	exempt_rental_receipts=$('#exempt_rental_receipts').val();
	if(exempt_rental_receipts=='')exempt_rental_receipts=0;
	//3
	taxable_rental_receipts=parseFloat(gross_rental_receipts)- parseFloat(exempt_rental_receipts);
	$('#taxable_rental_receipts').val(formatCurrency(taxable_rental_receipts));
	//4
	total_tax_collected=taxable_rental_receipts*0.05;
	$('#total_tax_collected').val(formatCurrency(total_tax_collected));
	total_tax_collected=parseFloat(formatCurrency(total_tax_collected));
	//5
	adjustments=$('#adjustments').val();
	if(adjustments=='')adjustments=0;
	//6
	total_tax_due=parseFloat(total_tax_collected) + parseFloat(adjustments);
	$('#total_tax_due').val(formatCurrency(total_tax_due));
	total_tax_due=parseFloat(formatCurrency(total_tax_due));
	//7
	if(total_tax_due>1200){
		less_collections_allowance=1200*0.025
	}else{
		less_collections_allowance=total_tax_due*0.025
	}
	$('#less_collections_allowance').val(formatCurrency(less_collections_allowance));
	less_collections_allowance=parseFloat(formatCurrency(less_collections_allowance));
	//8
	plus_penalty=$('#plus_penalty').val();
	if(plus_penalty=='')plus_penalty=0;
	if(parseFloat(plus_penalty)<50 && parseFloat(plus_penalty)>0){
		plus_penalty=50;
		$('#plus_penalty').val(formatCurrency(plus_penalty));
	}
	//9
	plus_interest=$('#plus_interest').val();
	if(plus_interest=='')plus_interest=0;
	//10
	current_period_due=(parseFloat(total_tax_due)-parseFloat(less_collections_allowance)) + (parseFloat(plus_penalty)+parseFloat(plus_interest));
	$('#current_period_due').val(formatCurrency(current_period_due));
	//11
	prior_outstanding_and_interest=$('#prior_outstanding_and_interest').val();
	if(prior_outstanding_and_interest=='')prior_outstanding_and_interest=0;
	//12
	total_amount_due=parseFloat(current_period_due)+parseFloat(prior_outstanding_and_interest);
	$('#total_amount_due').val(formatCurrency(total_amount_due));
}

function catchEnter(evt)
{
 // 13 is the ASCII value of an "Enter"
 if (evt.keyCode == 13)
 {
 // Prevents default action from Occuring in IE5+
	 if (evt.returnValue)
	 {
		 evt.returnValue = false;
	 }
	
	 // Prevents default action from Occuring in NN6+
	 if (evt.preventDefault)
	 {
	 	evt.preventDefault();
	 }
	 return true;
  } 
  return false; 
 }
function showCVVCodeExplain(){

	var tmpWind = window.open('', '_blank','directories=0, location=0, menubar=0, status=0,' 
						+'toolbar=0, resizable=0, scrollbars=0, width=610, height=530, left=300, top=300');
	var newDoc = tmpWind.document.open();
	var tempString = "<html><head><title>CVV Code Description</title></head><body><center>";
	tempString += "		<h3>CVV Code Description</h3>";
	tempString += "		<div style='text-align: justify;'>The CVV code helps to ensure that the customer has a legitimate credit card in his/her possession.<br/><br/>";
	tempString += "		<u><i>For Visa, MasterCard and Discover Cards:</i></u><br/>";
	tempString += "		The card code is a three-digit security code that is printed on the back of cards. The code typically appears at the end of the signature panel as shown on the example below.<br/><br/></div>";
	tempString += "		<img src='/images/CVV2CodeExplain.gif' /><br/>";
	tempString += "		<div style='text-align: justify;'><br/><u><i>For American Express Card:</i></u><br/>";
	tempString += "		The card code is a four-digit that is located above your account number of the face of your card.<br/></div>";
	tempString += "		<img src='/images/americanExp.gif' /><br/>";

	tempString += "		<input type='button' onclick='window.close()' value='Close Window'>";
	tempString += "</center></body</html>";
	newDoc.write(tempString);
		
	newDoc.close();
	tmpWind.focus();
}

function initDatePicker(dateFormat, elementId)
{
	var currentTime = new Date() ;
	var year = currentTime.getFullYear() ;
	var sDate = '01/01/' +(year-20) ;
	var strFilter = ".date-pick";
	if(elementId != null && elementId != "")
		strFilter = "#" + elementId;
	if(dateFormat!=null && dateFormat!="")
		sDate = '01/' +(year-20) ;
	$(strFilter).bind('blur',function(event) {
		if($(strFilter).val() == ""){
			$(strFilter).datePicker({startDate:sDate});
		};
	});
	$(strFilter).datePicker({startDate:sDate});
	
}
function blankDatePicker()
{
	var strFilter = ".date-pick";
	$(strFilter).datePicker({startDate:"1"});
	$("#startDate").val('');
	$("#endDate").val('');
	
	
}
function xstooltip_findPosX(obj) 
{
  var curleft = 0;
  if (obj.offsetParent) 
  {
    while (obj.offsetParent) 
        {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}
function xstooltip_findPosY(obj) 
{
    var curtop = 0;
    if (obj.offsetParent) 
    {
        while (obj.offsetParent) 
        {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}
function xstooltip_show(tooltipId, parentId, posX, posY)
{
	//alert(parentId);
	//alert(tooltipId);
    it = document.getElementById(tooltipId);
    if ((it.style.top == '' || it.style.top == 0) 
        && (it.style.left == '' || it.style.left == 0))
    {
        // need to fixate default size (MSIE problem)
        //it.style.width = it.offsetWidth + 'px';
        //it.style.height = it.offsetHeight + 'px';
    	
        img = document.getElementById(parentId); 
        
        // if tooltip is too wide, shift left to be within parent 
        if (posX + it.offsetWidth > img.offsetWidth) posX = img.offsetWidth - it.offsetWidth;
        if (posX < 0 ) posX = 0; 
        
        x = xstooltip_findPosX(img) + posX;
        y = xstooltip_findPosY(img) + posY;
        it.style.top = (y-20) + 'px';
        it.style.left = x + 'px';
    }
    it.style.visibility = 'visible'; 
}
function xstooltip_hide(id)
{
    it = document.getElementById(id); 
    it.style.top = '';
    it.style.left = '';
    it.style.visibility = 'hidden'; 
}

function submitForm(name){
	var test = $('[name='+ name +']');
	$('[name='+ name +']').submit();	
}

function setAttrList(list, attr, status){
	for(var i = 0; i < list.length; i++){
		$('#' + list[i]).attr(attr, status);
	}
}

function validateKeyPressIsValidKeywords(evt){
	var keyCode = (evt.which)?(evt.which):(evt.keyCode);
	var keychar = String.fromCharCode(keyCode);
	keychar = keychar.toLowerCase();
	if ( (('abcdefghijklmnopqrstuvwxyz0123456789 ').indexOf(keychar) > -1) //alphanumberic
		|| keyCode==37 || keyCode==39 	//left, right 
		|| keyCode==8 || keyCode==46 || keyCode==9 || keyCode == 45) 	//delete,backspace, tab, subtract
	{
		return true;
	}
	else
	{
		// Prevents default action from Occuring in IE5+
		if (evt.returnValue)
		{
			evt.returnValue = false;
		}

		// Prevents default action from Occuring in NN6+
		if (evt.preventDefault)
		{
			evt.preventDefault();
		}
		return false;
	}
}


function validateKeyPressIsPhone(evt){
	var keyCode = (evt.which)?(evt.which):(evt.keyCode);
	if ( ((keyCode > 47) && (keyCode < 58)) //number
		|| keyCode==37 || keyCode==39 	//left, right 
		|| keyCode==8 || keyCode==46 || keyCode==9 || keyCode == 45) 	//delete,backspace, tab, subtract
	{
		return true;
	}
	else
	{
		// Prevents default action from Occuring in IE5+
		if (evt.returnValue)
		{
			evt.returnValue = false;
		}

		// Prevents default action from Occuring in NN6+
		if (evt.preventDefault)
		{
			evt.preventDefault();
		}
		return false;
	}
}

function getInternetExplorerVersion() {
    var rv = -1; // Return value assumes failure.

    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}

function setWidthCbo(cbo, intWidth)
{
	var ieversion=getInternetExplorerVersion();
	if (ieversion>-1 && ieversion<9)
	{
		cbo.style.pixelWidth = intWidth;
	}
}
// return mm/dd/yyyy
function getCurrentDate(){
	var currentTime = new Date();
	var month = currentTime.getMonth() + 1;
	var day = currentTime.getDate();
	var year = currentTime.getFullYear();
	return month + "/" + day + "/" + year ;
}
function validateKeyPressIsDate(evt){
	var keyCode = (evt.which)?(evt.which):(evt.keyCode);
	if ( ((keyCode > 47) && (keyCode < 58)) //number
		|| keyCode==37 || keyCode==39 	//left, right 
		|| keyCode==47 //	forward slash 191 or 47 ? 
		|| keyCode==8 || keyCode==46 || keyCode==9 || keyCode == 45 ) 	//delete,backspace, tab, subtract
	{
		return true;
	}
	else
	{
		// Prevents default action from Occuring in IE5+
		if (evt.returnValue)
		{
			evt.returnValue = false;
		}

		// Prevents default action from Occuring in NN6+
		if (evt.preventDefault)
		{
			evt.preventDefault();
		}
		return false;
	}
}
function isBlankField(fieldID) {
	return (document.getElementById(fieldID) == null) || (trim(document.getElementById(fieldID).value) == "");
}
function getObject(id) {
	return document.getElementById(id);
}

function getValue(id){
	if (document.getElementById(id)== null) {
		return "";
	} else {
		return document.getElementById(id).value;
	}
}

function setValue(id, value){	
	document.getElementById(id).value = value;	
}

function setDisplay(id, value) {
	var elm = getObject(id);
	elm.style.display = value;	
}

function setFocus(id) {
	var elm = getObject(id);
	try{
		elm.focus();
	}catch(err){
		
	}
}
function compareFrDateToDate(strFromDate,strToDate){
	var dteFromDate = new Date(strFromDate);
	var dteToDate = new Date(strToDate);
	var result=true;
	if(dteFromDate > dteToDate)
    {
		result= false; 
    }
	return result;
}
function compareFrDatecurDate(strFromDate){
	var dteFromDate = new Date(strFromDate);
	var dayobj=new Date();
	var strmon=dayobj.getMonth()+1;
	var strday=dayobj.getDate();
	var stryear=dayobj.getFullYear();
	var strcurdate=strmon+"/"+strday+"/"+stryear;
	var dtecurDate = new Date(strcurdate);
	var result=true;
	if(dteFromDate < dtecurDate)
    {
		result= false; 
    }
	return result;
}
function trim(str){
	return str.replace(/^\s+|\s+$/g,"");
}
function validateDateField(dateField) {
	if (dateField.value.length > 0) {
		dArray = dateField.value.split('/');
		errorMsg = "Please enter a valid date (mm/dd/yyyy)!"; 
						
		if (dArray.length == 3 && !(isNaN(dArray[0]) || isNaN(dArray[1]) || isNaN(dArray[2]))) {
			month = Number(dArray[0]);
			day = Number(dArray[1]);
			year = Number(dArray[2]);
			errorMsg = check3FldDate(month, day, year);
			
			if (errorMsg.length == 0) {
				dateField.value = (month < 10 ? "0" : "") + month + "/" + (day < 10 ? "0" : "") + day + "/" + year;
			}
		}
		
		if (errorMsg.length > 0) {
			dateField.focus();
			alert(errorMsg);
			return false;
		}
	}
	
	return true;
}
function check3FldDate(month, day, year) {  
	if ((month.length < 1) && (day.length < 1) && (year.length < 1)) {
    	return "";
  	}

  	// Make sure the formats for the fields are ok.
  	if (!month || isNaN(month) || month.length < 1) {
    	return "Month must be a number";
  	}
  	else if (!day || isNaN(day) || day.length < 1) {
    	return "Day must be a number";
  	}
  	else if ((isNaN(year)) || (year.length < 4) || (year.length > 4)) {
    	return "Year must be a number";
  	}

  	// Basic error checking.
  	if (month < 1 || month > 12)  {
    	return "Month must be a number in range 1 to 12";
  	}
  	else if (day < 1 || day > 31) {
    	return "Day must be a number in range 1 to 31";
  	}
  	else if (year < 1880 || year > 9999) {
    	return "Year must be a number in range 1880 to 9999";
  	}

  	// Advanced error checking.
  	if (month == 4 || month == 6 || month == 9 || month == 11){
    	if (day == 31) {
	    	return "Day is invalid with the given month";
    	}
  	}

	// February and leap year check.
  	if (month == 2 && day > 28) {
    	if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
    	  	// Check the day.  If it is larger than 29, it is invalid.
      		if (day > 29) {
        		return "Day is invalid with the given month";
      		}
    	} 
    	else {
			return "Day is invalid with the given month";    	
		}
  	}
  	
  	return "";
}
function confirmDelete(strName){
	return confirm('Are you sure you want to delete ' + strName + " ?");
}

function clearSearchZone(zoneId){	
	var inputTexts = document.getElementById(zoneId).getElementsByTagName('input');
	for(var i= 0; i< inputTexts.length; i++){		
		switch (inputTexts[i].type){
			case "text":
				inputTexts[i].value = "";
				break;
			case "checkbox":
				inputTexts[i].checked = false;				
				break;
		}
	}
	var comboBoxes = document.getElementById(zoneId).getElementsByTagName('select');
	for (var i = 0; i < comboBoxes.length; i++) {
		comboBoxes[i].value = comboBoxes[i].options[0].value;		
	}
}

// customize Dropdown List

//function createDropDown(sourcename,targetname){
//    var source = $("#"+sourcename);
//    var selected = source.find("option[selected]");  // get selected <option>
//    var selectedName='';
//    var selectedValue='';
//    if(!selected.val()){
//    	//document.getElementById(sourcename).selectedIndex=0;
//    	source = document.getElementById(sourcename);
//    	var selectedIndex=document.getElementById(sourcename).selectedIndex;
//    	selected=source.options[selectedIndex];
//    	selectedName=selected.text;
//    	selectedValue=selected.value;
//    }else{
//    	selectedName=selected.text();
//    	selectedValue=selected.val();
//    }
//    var options = $("option", source);  // get all <option> elements
//    // create <dl> and <dt> with selected value inside it
//    //$("body").append('<dl id="'+targetname+'" class="dropdown"></dl>')
//    $("#" + targetname).append('<dt><a href="javascript:clickOnDropDown(\''+sourcename+'\',\''+targetname+'\')">' + selectedName + 
//        '<span class="value">' + selectedValue + 
//        '</span></a></dt>')
//    $("#" + targetname).append('<dd><ul></ul></dd>')
//    // iterate through all the <option> elements and create UL
//    options.each(function(){
//        $("#" + targetname+" dd ul").append('<li><a id="'+$(this).val()+'" name="'+$(this).val()+'" href="javascript:selectOnDropDown(\''+ $(this).val() + '\',\''+sourcename+'\',\''+targetname+'\')">' + 
//            $(this).text() + '<span class="value">' + 
//            $(this).val() + '</span></a></li>');
//    });
//    $("#"+sourcename).hide();
//}
//function clickOnDropDown(sourcename,targetname){
//    $("#"+targetname+" dd ul").toggle();
//}

//function selectOnDropDown(selectedName,sourcename,targetname){
//	
//	var text = $("#" + selectedName).html();
//	$("#"+targetname+" dt a").html(text);
//	$("#"+targetname+" dd ul").hide();
//	//$(this).val($("#"+targetname+" dd ul li a").find("span.value").html());
//	$("#"+sourcename).val(getSelectedValue(targetname)); 
//	$("#"+sourcename).change();   
//}

function getSelectedValue(id) {
    return $("#" + id).find("dt a span.value").html();
}

function addToolTipToDropDown(el)
 {
     $(el).find("option:[title='']").each(function () {
           $(this).attr("title",$(this).text());
        });  
 }
 
 function DisplayList(selectList){
			 var thisList = document.getElementById(selectList);
			 if (thisList){
				if (thisList.style.display != 'block') {
					thisList.style.display = 'block';
				}
				else
				{
					thisList.style.display = 'none'
				}
			 }
	
		}
		
function selectItem(list){
	jQuery.each($('span[id*="select0"]'), function() {
			this.style.textDecoration = 'none';				
		});
	//alert(document.getElementById(list).innerHTML);
	
	document.getElementById('hiddSelectedTemp').value =list.substr(7);//remove 'selector0' to get category id
	document.getElementById('selected').innerHTML = document.getElementById(list).innerHTML;
	document.getElementById('selectList').style.display = 'none';
}

function mouseOverItem(list){
	jQuery.each($('span[id*="select0"]'), function() {
			this.style.textDecoration = 'none';				
		});
	document.getElementById(list).style.textDecoration = 'underline'; 
}

function ViewImage(imagePath){
	document.getElementById('viewProduct').innerHTML = '<img  onload="vZoom.add(this, \'' + imagePath + '\');"  src="' + imagePath + '" id="imgProduct" class="scaleLargeImage" alt="" title="" />';
}
function isMobile(){
	return $("#ismobile").val()=="true";
}
function ViewImage_mobile(imagePath, fullImagePath){
	var html = '';
	html += '<a href="#" onclick="ViewFullImage_mobile();">';
	html += '<img id="imgProduct" border="0" src="' + imagePath + '" />';
	html += '</a>';
	document.getElementById('viewProduct').innerHTML = html;
	var html2 = '';
	html2 += '<a href="#" onclick="ViewNomalImage_mobile();">';
	html2 += '<img id="imgProductFull" style="display:none" border="0" src="' + fullImagePath + '" />';
	html2 += '</a>';
	html2 += '<br/><a href="#"  class="button" onclick="ViewNomalImage_mobile();">Back</a>';
	document.getElementById('fullImageDetail').innerHTML = html2;
}

function ViewFullImage_mobile(){
	$("#divHeaderTop1").hide();
	$("#divHeaderTop2").hide();
	$("#seachboxDiv").hide();
	$("#divProductDetail").hide();
	$("#dotbarpd").hide();
	$("#Lnd").hide();
	$("#footer").hide();
	$("#imgProductFull").show();
	$("#fullImageDetail").show();
}
function ViewNomalImage_mobile(){
	$("#divHeaderTop1").show();
	$("#divHeaderTop2").show();
	$("#seachboxDiv").show();
	$("#divProductDetail").show();
	$("#dotbarpd").hide();
	$("#Lnd").show();
	$("#footer").show();
	$("#imgProductFull").hide();
	$("#fullImageDetail").hide();
}
// like function ucfirst in PHP
function ucfirstCharacter(strInput){
	if(strInput==null||strInput=="")return strInput;
	return strInput.charAt(0).toUpperCase() + strInput.slice(1);
}
// parameter: n is number, dec is number of decimal
function decimal(n,dec) {
	if(n=="")return 0;
	n = parseFloat(n);
	if(!isNaN(n)){
		if(!dec) var dec= 0;
		var factor= Math.pow(10,dec);
		return Math.floor(n*factor+((n*factor*10)%10>=5?1:0))/factor;
	}else{
		return n;
	}
}
// go to login page
function goLoginPage(){
	window.location = document.getElementById("urldefault").value + 'login';
}

function gotoPage(page){
	window.location = page;
}

function showTab(){
	if(max_waiting > 0){
		$('.tabs li a[href=\#tabs-2]').click();
	}
	else{
		max_waiting = 100;
	}
}
function waitingFunction(func_name, is_continue){
	if(is_continue == false){
		max_waiting = 100;
	}
	else if(max_waiting > 0){
		max_waiting--;
		setTimeout("waitingFunction('"+ func_name +"', assignToVariableOptional = func_name)", wait_time);
	}else max_waiting = 100;
}

function showDefaultSearchBlur(element, text){
	if(element.value == ""){
		element.value = text;
	}
}
function showDefaultSearchFocus(element, text){
	if(element.value == text){
		element.value = "";
	}
}

function getCardType(number)
{
	var re = new RegExp("^4");
	if (number.match(re) != null)
		return "Visa";
	re = new RegExp("^(34|37)");
	if (number.match(re) != null)
		return "American Express";
	re = new RegExp("^5[1-5]");
	if (number.match(re) != null)
		return "Master Card";
	re = new RegExp("^6011");
	if (number.match(re) != null)
		return "Discover";
	return "";
}
function setCardTypeByNum(number, cardTypeId){
	var cardType = getCardType(number);
	if(cardType != ""){
		$('#'+ cardTypeId).val(cardType);
	}
}

function DisplayImage(obj,imagePath)
{
	document.getElementById(obj).src=imagePath;
}
function callOutOfSession(data, href){
	if(data == "Out Of Session"){
		window.location = document.getElementById("urldefault").value + href;
		return true;
	}
	return false;
}

function switchEditViewDIV(editDIV, viewDIV, flag){
	if(flag){
		$(editDIV).show();
		$(viewDIV).hide();
	}else{
		$(editDIV).hide();
		$(viewDIV).show();
	}
}

function setValueMultiSelect(valueString, clientsName){
	var values = valueString.split(",");
	var obj = document.getElementsByName(clientsName);
	//reset value
	for (var i = 0; i < obj.length; i++) {
		obj[i].checked = false;
	}
	for (var i = 0; i< values.length; i++) {
		for (var k = 0; k< obj.length; k++) {
			var obj_value = obj[k].value;			
			if (obj_value == values[i]){							
				obj[k].click();
			} 	
		}
	}
}

function callBlockUI(){
	if(isMobile()==false){
		$.blockUI({ message: "<h2>Please wait ...</h2>" });
	}else{
		$.blockUI({ message: "<h3>Please wait ...</h3>", css: {width:'45%'}});
	}
	
}

function showHideItem(is_show, item_id){
	if(is_show) $("#"+ item_id).show();
	else $("#"+ item_id).hide();
}

function redirect_url(url)
{
    window.location=url;
}